// 设置文档标题需要用这个方法 不然在ios微信浏览器中有bug
const setTitle = title => {
  title = formatTitle(title)
  document.title = title
  var mobile = navigator.userAgent.toLowerCase()
  if (/iphone|ipad|ipod/.test(mobile)) {
    var iframe = document.createElement('iframe')
    iframe.style.display = 'none'
    // 替换成站标favicon路径或者任意存在的较小的图片即可
    // iframe.setAttribute('src', '/favicon.ico')
    // iframe.setAttribute('src','/wt_logo.png')
    var iframeCallback = function () {
      setTimeout(function () {
        iframe.removeEventListener('load', iframeCallback)
        document.body.removeChild(iframe)
      }, 0)
    }
    iframe.addEventListener('load', iframeCallback)
    document.body.appendChild(iframe)
  }
}

function formatTitle(title) {
  let values = title
  if (values.length > 17) {
    let replaceVal = values.substring(17, title.length)
    values = values.replace(replaceVal, '...')
  }
  return values
}
export default setTitle